package com.wenx.jvm;

import com.google.common.collect.Lists;

import java.util.List;

public class HeapTest {

    public static void main(String[] args) {
        //获取最大内存
        long maxMemory = Runtime.getRuntime().maxMemory();
        //目前总内存
        long totalMemory = Runtime.getRuntime().totalMemory();
        //空闲内存
        long freeMemory = Runtime.getRuntime().freeMemory();

        System.out.println(String.format("max = %fMB", maxMemory / (double) 1024 / 1024));
        System.out.println(String.format("total = %fMB", totalMemory / (double) 1024 / 1024));
        System.out.println(String.format("free = %fMB", freeMemory / (double) 1024 / 1024));

        List<Object> list = Lists.newArrayList();

        while (true) {
            list.add(new Object());
        }

    }

}
